﻿using Pay.DTO;
using Pay.TO;
using Pay.IService;
using System.Web.Mvc;

namespace Pay.Web.Areas.Admin.Controllers {
	public class PaymentController : AdminController {
		private IPaymentService _iPaymentService;

		public PaymentController(IPaymentService iPaymentService) {
			_iPaymentService = iPaymentService;
		}

		public JsonResult Get(long id) {
			var result = _iPaymentService.Get(id);
			return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
		}
		public JsonResult Gets() {
			var result = _iPaymentService.Get();
			return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
		}
		[HttpPut]
		[ValidateInput(false)]
		public JsonResult Put(long id) {
			var dto = _iPaymentService.Get(id);
			TryUpdateModel(dto);
			var result = _iPaymentService.Update(dto);
			return Json(ResultToJson.Json(result > 0 ? "保存成功" : "没有修改任何内容", result), JsonRequestBehavior.AllowGet);
		}
		[HttpPost]
		[ValidateInput(false)]
		public JsonResult Post(payment_dto dto) {
			var result = _iPaymentService.Add(dto);
			return Json(ResultToJson.Json(result > 0 ? "保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);
		}
		[HttpDelete]
		public JsonResult Delete(long id) {
			var result = _iPaymentService.Delete(id);
			return Json(ResultToJson.Json(result > 0 ? "删除成功" : "删除失败", result), JsonRequestBehavior.AllowGet);
		}
	}
}